﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NetPE.Core.Metadata.Heaps;
using NetPE.Core.Metadata.Tables;

namespace NetPE.Dialogs
{
    public partial class NewTableDialog : BaseDialog
    {
        public NewTableDialog(MdTablesEditor h)
            : base(h)
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                TableType t = (TableType)Enum.Parse(typeof(TableType), comboBox1.SelectedText);
                if (((Object as MdTablesEditor).Object as TablesHeap)[t] != null)
                {
                    MessageBox.Show("Already exist!");
                    return;
                }
                ((Object as MdTablesEditor).Object as TablesHeap)[t] = new MetadataTable((Object as MdTablesEditor).Object as TablesHeap, t);
                (Object as MdTablesEditor).treeView1.Nodes.Add(new TreeNode(t.ToString()) { Tag = ((Object as MdTablesEditor).Object as TablesHeap)[t] });
            }
            catch
            {
                MessageBox.Show("Error!");
                this.DialogResult = DialogResult.None;
            }
        }
    }
}
